package com.xpertline.ui.validator;

import org.apache.commons.lang3.StringUtils;
import org.jdesktop.beansbinding.Validator;

/**
 * Validate the year-of-birth field. This year can't be in the future.
 */
public final class UrlValidator extends Validator<String> {

	@Override
	public Result validate(String url) {
		if (StringUtils.isEmpty(url)) {
			return null;
		}
		// Assigning the url format regular expression
		String urlPattern = "^http(s{0,1})://[a-zA-Z0-9_/\\-\\.]+\\.([A-Za-z/]{2,5})[a-zA-Z0-9_/\\&\\?\\=\\-\\.\\~\\%]*";
		if (!url.matches(urlPattern)) {
			return new Result(null, "Url is not correct format.");
		}
		return null;
	}
}
